package cn.iocoder.boot.book_250712.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session) {
        // 判空
        if (!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return false;
        }
        // 判断账密对否
        if ("admin".equals(userName) && "admin".equals(password)) {
            // 将用户名存储到 session 中
            session.setAttribute("userName", userName);
            return true;
        }
        return false;
    }
}
